package com.info.zhiduoduo.pay.sdk.pinganbank.service;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.info.zhiduoduo.common.configs.ZhaoShangPayConfig;
import com.info.zhiduoduo.common.constants.SmartResult;
import com.info.zhiduoduo.common.constants.StatusMsg;
import com.info.zhiduoduo.common.exception.SmartException;
import com.info.zhiduoduo.common.utils.ImgBase64Util;
import com.info.zhiduoduo.common.utils.StringUtil;
import com.info.zhiduoduo.pay.formbean.zhaoshangbankpay.QueryTransactionInfoFormBean;
import com.info.zhiduoduo.pay.formbean.zhaoshangbankpay.ZhaoShangAgentPayFormBean;
import com.info.zhiduoduo.pay.sdk.zhaoshangbank.model.common.HeadReqDTO;
import com.info.zhiduoduo.pay.sdk.zhaoshangbank.model.common.HeadRespDTO;
import com.info.zhiduoduo.pay.sdk.zhaoshangbank.model.common.RequestDTO;
import com.info.zhiduoduo.pay.sdk.zhaoshangbank.model.common.ResponseDTO;
import com.info.zhiduoduo.pay.sdk.zhaoshangbank.model.request.agentpay.QueryReceiptReqDTO;
import com.info.zhiduoduo.pay.sdk.zhaoshangbank.model.request.agentpay.QueryTransactionInfoReqDTO;
import com.info.zhiduoduo.pay.sdk.zhaoshangbank.model.response.agentpay.*;
import com.info.zhiduoduo.pay.sdk.zhaoshangbank.util.HttpUtils;
import com.info.zhiduoduo.repository.entity.pay.PaymentMerchant;
import com.pingan.openbank.api.sdk.client.ApiClient;
import com.pingan.openbank.api.sdk.common.http.HttpResult;
import com.pingan.openbank.api.sdk.entity.SdkRequest;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.io.File;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;

@Slf4j
@Service
public class PingAnBankPayApiService {
    /**
     * 平安银行查询账号接口 BEDL_4001
     *
     * @param formBean
     * @return
     */
    public SmartResult balanceQuery(ZhaoShangAgentPayFormBean formBean) {
        PaymentMerchant paymentMerchant = new PaymentMerchant().selectById(formBean.getPaymentMerchant());
        String caFile = paymentMerchant.getCaFile();
        ApiClient apiClient = ApiClient.getInstance(caFile);
        JSONObject requestBody = new JSONObject();
        Calendar cal = Calendar.getInstance();
        //系统流水号，规范：用户短号（6位）+日期（6位）+随机编号（10位）
        requestBody.put("MrchCode", paymentMerchant.getMerchantNo());
        requestBody.put("CnsmrSeqNo", formBean.getTradeNo());
        requestBody.put("Account", paymentMerchant.getBankCard()+1);

        System.out.println("requestBody=" + requestBody);
        SdkRequest sdkRequest = new SdkRequest();
        sdkRequest.setInterfaceName("V1.0/bedl/CorAcctBalanceQuery");
        sdkRequest.setBody(requestBody);
        HttpResult httpResult = apiClient.invoke(sdkRequest);
        return SmartResult.success(httpResult.getData());
    }
}
